<?php
//
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get_detail';
if($_RQ['op']=='get_detail'){
	$return=model('jy_weishop/page/goods_detail')->getmain($return);
	$return['registerurl']=$return['pluginset']['app_saleurl']?:'';
	$sharelink='jy_pay2shop/goods.detail//id='.$return['goods']['id'].'&fromuser='.$_SESSION['uid'];
	$return['sharedata']['link']=custom_url($sharelink,true);
	$payset=uni_setting('pay');
	$credit3_rate=$payset['credit3_rate']?:1;
	$return['goods']['credit3']=$return['goods']['api_data']['credit3price']?:price($return['goods']['price']*$credit3_rate,'int');
	$return['goods']['isposter']=0;
	$return['htmls']='';
	$keywords=$return['goods']['share_keywords']?:$return['goods']['title'].','.$return['sharedata']['desc'];
	$desc=$return['sharedata']['desc'];
	set_html('title',$return['goods']['title']?$return['goods']['title'].'-'.$return['shopset']['title']:'商品详情');
	set_html('keywords',$keywords);
	set_html('description',$desc);
	exi($return);
}
if($_RQ['op']=='check_buy'){
	$goodsid=intval($_RQ['goodsid'])?:$_SESSION['goodsid'];
	if(!$goodsid){
		exi('请选择商品！','error');
	}
	$goods=pdo_get('jy_weishop_goods',array('id'=>$goodsid),array('id','title','no_onebuy','merchid'));
	if($goods['no_onebuy']==1 || $goods['no_onebuy']==3){
		exi('该商品，不能单独购买！','error');
	}
	model('jy_weishop/activity/sales')->check_sale_new(array(array('goodsid'=>$goodsid)));
	model('jy_weishop/goods')->check_buy($goodsid,$_RQ['num'],$_RQ['optionsid']);
	$resurl='jy_pay2shop/order.create//goodsid='.$goodsid.'&num='.$_RQ['num'].'&optionsid='.$_RQ['optionsid'].'&addressid='.$_RQ['addressid'].'&storeid='.$_RQ['storeid'].'&roomid='.$_RQ['roomid'].'&dayid='.$_RQ['dayid'].'&out_time='.$_RQ['out_time'];
	if($_RQ['isresurl']){
		exi($resurl);
	}else{
		exi('','',$resurl);
	}
}